package com.practice.controller.admin;

import com.practice.common.result.Result;
import com.practice.pojo.admin.dto.AdminMenuDTO;
import com.practice.pojo.admin.vo.AdminChildrenVO;
import com.practice.service.admin.AdminMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys_menu")
@Slf4j
public class AdminMenuController {

    @Autowired
    private AdminMenuService adminMenuService;

    //在sql中判断del_flag是否为1,是则不显示(逻辑删除)
    @GetMapping("/allData")
    public Result AllDate() {
        AdminChildrenVO adminChildrenVO = new AdminChildrenVO();
        adminChildrenVO.setId(0);
        return Result.success(adminMenuService.showAllDate(adminChildrenVO));
    }

    @GetMapping("/rowInfo")
    public Result rowInfo(String id) {
        return Result.success(adminMenuService.rowInfo(Integer.valueOf(id)));
    }

    @PostMapping("/add")
    public Result add(@RequestBody AdminMenuDTO adminMenuDTO) {
        adminMenuService.add(adminMenuDTO);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody AdminMenuDTO adminMenuDTO) {
        adminMenuService.update(adminMenuDTO);
        return Result.success();
    }

    //逻辑删除
    @GetMapping("/del")
    public Result delete(String id) {
        adminMenuService.delete(Integer.valueOf(id));
        return Result.success();
    }
}
